package com.itheima.servletcontext;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.function.DoubleBinaryOperator;

@WebServlet("/qu")
public class QuServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("进行取钱操作 取50000块钱");
        //从servletContext获取出来钱
        ServletContext servletContext = getServletContext();
        //使用get功能  因为默认是Object类型 所以进行强转
        Double money = (Double) servletContext.getAttribute("money");
        System.out.println("现在有:"+money);
        System.out.println("取出50000");
        money=money-50000;
        //取完钱 是不是要更新一下
        servletContext.setAttribute("money",money);

        System.out.println("钱已经取出来了");

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write("取出了5W块，还剩"+money);

    }
}
